package studentsOffice;



import degreeAndSyllabus.EnrolledInDegree;
import degreeAndSyllabus.SubjectInPlan;
import util.MyDate;

/**
 * 
 * @author Maria Laura Medici
 *
 */
public class EquivalenceProcess {
	
	/* ******************************** Variables ******************************** */
	private MyDate date;
	private SubjectInPlan solicitSubject;
	private String docentName;
	private String state;
	private EnrolledInDegree student;
	
	
	/* ******************************* Constructor ******************************* */
	
	public EquivalenceProcess(MyDate date,SubjectInPlan materiaEquivalente, String docentOk, EnrolledInDegree alumno){
		this.date = date; 
		this.docentName = docentOk; 
		this.solicitSubject = materiaEquivalente; 
		this.student = alumno;
		this.state = "En proceso";
	}
	
	
	/* ******************************** Get & Set ******************************** */
	public void setDate(MyDate date) {
		this.date = date;
	}
	public MyDate getDate() {
		return date;
	}

	public void setSolicitSubject(SubjectInPlan equivalentSubject) {
		this.solicitSubject = equivalentSubject;
	}
	public SubjectInPlan getSolicitSubject() {
		return solicitSubject;
	}
	public void setDocentName(String docentName) {
		this.docentName = docentName;
	}
	public String getDocentName() {
		return docentName;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getState() {
		return state;
	}
	public void setStudent(EnrolledInDegree student) {
		this.student = student;
	}
	public EnrolledInDegree getStudent() {
		return student;
	}
	
	/* ********************************* Metodos ********************************* */
	/**
	 * Decide si aceptar un o no una equivalencia de materias
	 */
	public void takeADecision(StudentsOffice oficinaAlumnos){
		  if(this.getStudent().aproboMaterias(this.getSolicitSubject().getMateriasEquivalentes())){
			  this.setState("Aprobado");
			  this.realizarEquivalencia();
			  oficinaAlumnos.addEquivalence(this); 
		  }
		  else{this.setState("Rechazado");
		       oficinaAlumnos.addRejectedEquivalence(this);}
	}

/**
 * Realiza la equivalencia, hace los cambios de materias
 */
	private void realizarEquivalencia() {
		int nuevaNota = this.devolverMejorNotaDeMateriasEquivalentes();
	
		for(SubjectInPlan materiaAprobada :this.getSolicitSubject().getMateriasEquivalentes()){
			this.getStudent().getMateriasCursadas().remove(materiaAprobada);
		}
		
		this.getStudent().getMateriasCursadas().put(this.getSolicitSubject(), nuevaNota);
	}
	
	/**
	 * Busca de las materias equivalentes la mejor nota
	 * @return int
	 */
	public int devolverMejorNotaDeMateriasEquivalentes(){
		int nuevaNota =0;
		for(SubjectInPlan materiaAprobada :this.getSolicitSubject().getMateriasEquivalentes()){
			if(nuevaNota < this.getStudent().getMateriasCursadas().get(materiaAprobada)){
				nuevaNota = this.getStudent().getMateriasCursadas().get(materiaAprobada);
			}
		}
		return nuevaNota;
	}
	
	/**
	 * Imprime el estado del proceso de equivalencia
	 */
	public void verEstado(){
		System.out.print(this.getState());
	}
}
